import logging

import colorlog


def setup_logger():
    # 获取根日志记录器并设置日志级别
    root_logger = logging.getLogger()
    root_logger.setLevel(logging.DEBUG)

    # 创建控制台处理器并设置日志级别
    console_handler = logging.StreamHandler()
    console_handler.setLevel(logging.DEBUG)

    # 设置带有颜色的日志格式
    color_formatter = colorlog.ColoredFormatter(
        "%(log_color)s%(asctime)s - %(name)s - %(levelname)s - %(message)s",
        datefmt="%Y-%m-%d %H:%M:%S",
        log_colors={
            "DEBUG": "white",  # 设置为白色，便于区分
            "INFO": "green",
            "WARNING": "yellow",
            "ERROR": "red",
            "CRITICAL": "bold_red",
        },
    )
    console_handler.setFormatter(color_formatter)

    # 添加处理器到日志记录器
    root_logger.addHandler(console_handler)


# 调用 setup_logger 函数进行配置
setup_logger()

# 获取配置好的日志记录器
logger = logging.getLogger()
